package com.woniuxy.admin.controller;


import com.woniuxy.admin.entity.AdminLogin;
import com.woniuxy.admin.entity.AdminRole;
import com.woniuxy.admin.service.AdminRoleService;
import com.woniuxy.admin.util.JWTUtil;
import com.woniuxy.admin.util.TokenUtil;
import com.woniuxy.core.annotation.Permission;
import com.woniuxy.core.util.Result;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ...
 * @since 2024年05月22日
 */
@RestController
@RequestMapping("/adminRole")
@Api(tags="管理员角色")
public class AdminRoleController {
    @Resource
    private AdminRoleService adminRoleService;

    @Resource
    private TokenUtil tokenUtil;

    /**
     * 查询所有角色
     * @return
     */
    @GetMapping("/loadAllRole")
    @ApiOperation("查询所有角色")
    @ApiResponses({
            @ApiResponse(code = 200,message = "OK",response = AdminRole.class)
    })
    @Permission(roles = {"超级管理员","管理员"})
    public Result loadAllRole(){
        List<AdminRole> roles = adminRoleService.list();
        return Result.success("查询所有角色成功",roles);
    }

    /**
     * 根据账号Id查找拥有的角色
     * @param token 携带账号Id的请求头
     * @return
     */
    @GetMapping("/loadAllRoleByAccountId")
    @ApiOperation("根据账号Id查询角色")
    @ApiResponses({
            @ApiResponse(code = 200,message = "OK",response = AdminRole.class)
    })
    public Result loadAllRoleByAccountId(@RequestHeader  String token){
        Integer accountId = tokenUtil.getAccountId(token);
        AdminRole adminRole  = adminRoleService.loadAllRoleByAccountId(accountId);
        return Result.success("根据账号Id 查询所拥有角色成功",adminRole);
    }

    /**
     * 根据账号Id查找拥有的角色
     * @param accountId 账号Id
     * @return
     */
    @GetMapping("/loadAllRoleByAccountId1")
    @ApiOperation("根据账号Id查询角色")
    @ApiResponses({
            @ApiResponse(code = 200,message = "OK",response = AdminRole.class)
    })
    @ApiImplicitParam(name = "accountId",value = "账号id")
    public Result loadAllRoleByAccountId1(Integer accountId){
        Integer roleId  = adminRoleService.loadAllRoleByAccountId(accountId).getRoleId();
        return Result.success("根据账号Id 查询所拥有角色成功",roleId);
    }

}

